/*
 * 
 * Created on Jul 22, 2005
 */
package remato.client.view.editor.usertypes;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;

import remato.client.model.AbstractPropertySpesification;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: PropertySpecificationDragSourceListener.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 * 
 */
public class PropertySpecificationDragSourceListener implements DragSourceListener {

    private StructuredViewer viewer;

    public PropertySpecificationDragSourceListener(StructuredViewer viewer) {
       this.viewer = viewer;
    }

    AbstractPropertySpesification dragData;
    
    /**
     * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
     */
    public void dragStart(DragSourceEvent event) {
        Object o = ((IStructuredSelection)viewer.getSelection()).getFirstElement();
//        System.out.println("Type: " + o.getClass().getName());
        event.doit = !viewer.getSelection().isEmpty() &&  o instanceof AbstractPropertySpesification;
        if (event.doit) {
            dragData = (AbstractPropertySpesification) o ;
        }
    }

    /**
     * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
     */
    public void dragSetData(DragSourceEvent event) {
        event.data = dragData;
    }

    /**
     * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
     */
    public void dragFinished(DragSourceEvent event) {
        if (!event.doit) {
            return;
        }
    }
    
}
/**
 * 
 * Changelog:
 * 
 * $Log: PropertySpecificationDragSourceListener.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.1  2005-12-03 14:38:48  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/11/16 16:43:28  petterei
 * mye testing...
 *
 * Revision 1.2  2005/09/27 17:06:19  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/08/28 18:01:26  peide3
 * save in Eclipse-way
 * dynamic propertyspecifications bug fixed
 * dnd to deside order of property specification
 * ItemType to make convertion more understandable
 *
 *
 */
